<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        width: 200px;
        height: 200px;
        border: 1px solid green;
      }
    </style>
  </head>
  <body>
    <div id="box"></div>
    <button id="btn1">绑定</button>
    <button id="btn2">解绑</button>
    <script>
      //DOM0 的绑定和解绑
      //   document.getElementById('btn1').onclick = function () {
      //     // document.getElementById('box').style.display = 'none';
      //     console.log('hhh')
      //   };
      //   document.getElementById('btn2').onclick = function () {
      //     document.getElementById('btn1').onclick = null;
      //   };

      //DOM2的绑定和解绑
      var boxEle = document.getElementById('box');
      var btn1 = document.getElementById('btn1');
      var btn2 = document.getElementById('btn2');
      btn1.addEventListener('click', test )
      function test(){
        boxEle.style.display = 'none';
      }
      btn2.addEventListener('click',function(){
        btn1.removeEventListener('click', test)
      });
      


    </script>
  </body>
</html>
